<template>
	<view class="p-3">
		<view class="card bg-white rounded-lg p-2 flex align-center justify-between mb-3" v-for="(item,index) in list"
			:key="index">
			<view class="">
				<view class="flex align-center">
					<image src="../../../static/img/ic_default_head.png" style="width:100rpx;height: 100rpx;" mode="">
					</image>
					<view class="ml-2">
						<view class="mb-1">{{item.user_name}}</view>
						<view class="mb-1">{{item.dl}}</view>
					</view>
				</view>
				<view class="">IMEI：{{item.imei}}</view>
			</view>
			<view style="width: 200rpx; height: 60rpx; background-color: #FFA800; border-radius: 60rpx;"
				v-if="item.sbstatus=='已开机'" class="flex align-center justify-center font28 colorfff">
				{{item.sbstatus}}
			</view>
			<view style="width: 200rpx; height: 60rpx; background-color: #999999; border-radius: 60rpx;"
				v-else class="flex align-center justify-center font28 colorfff">
				{{item.sbstatus}}
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				parentId: 0,
				list: []
			}
		},
		onLoad() {
			let _this = this;
			_this.getData();
		},
		methods: {
			getData() {
				let this_ = this;
				this_.list = [];
				var arr = uni.getStorageSync('userInfo').class_info;
				arr.map((item) => {
					let opts = {
						url: 'device/elec?serialNo=' + item.imei + '&AuthToken=' + uni
							.getStorageSync('userInfo').token
					};
					let param = {
						serialNo: item.imei,
						AuthToken: uni.getStorageSync('userInfo').token
					};
					this_.$http.httpDeveiceRequest(opts, param).then(
						res => {
							console.log(res.data.ReturnData.deviceStatus);
							if (res.data.ReturnMsg == "success") {
								item.dl = res.data.ReturnData.message;
								let opts1 = {
									url: 'device/devicestatus?serialno=' + item.imei,
								};
								let param1 = {
									serialno: item.imei
								};
								this_.$http.httpDeveiceRequest(opts1, param1).then(
									res => {
										console.log(res.data.ReturnData.deviceStatus);
										if (res.data.ReturnMsg == "success") {
											let status = res.data.ReturnData.deviceStatus;
											if (status == "ONLINE") {
												item.sbstatus = "已开机"
											} else if (status == "OFFLINE") {
												item.sbstatus = "已关机"
											} else {
												item.sbstatus = "已关机"
											}
											this.list.push(item)
										}

									},
									error => {
										console.log(error);
									}
								);
							} else {
								this.list.push(item)
							}

						},
						error => {
							this.list.push(item)
						}
					);

				})

			}
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
	}
</style>
